package com.example.smartcitymovie.ui.movie;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.os.Bundle;
import android.util.Log;

import com.bumptech.glide.Glide;
import com.example.smartcitymovie.MyApplication;
import com.example.smartcitymovie.R;
import com.example.smartcitymovie.bean.MovieMessageBean;
import com.example.smartcitymovie.common.ShowFragmentList;
import com.example.smartcitymovie.dataRepo.ApiData;
import com.example.smartcitymovie.databinding.ActivityChooseMovieThreaterBinding;
import com.example.smartcitymovie.utils.OkHttpUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class ChooseMovieThreaterActivity extends AppCompatActivity {

    ActivityChooseMovieThreaterBinding binding;
    private int id;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityChooseMovieThreaterBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        getSupportActionBar().setTitle("选择影院");
        id = getIntent().getIntExtra("id",0);
        initView();
    }

    private void initView() {
        MovieMessageBean movieMessageBean = ApiData.getMovieDetailDataById(id);
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Glide.with(binding.IVCoverTwo).load(movieMessageBean.getData().getCover()).placeholder(R.drawable.ic_baseline_broken_image_24).into(binding.IVCoverTwo);
                MyApplication.getMovieType().forEach((key,value)->{
                    if (key==Integer.valueOf(movieMessageBean.getData().getPlayType())){
                        binding.TVMovieTypeTwo.setText(value);
                    }
                });
                binding.TVMovieNameTwo.setText(movieMessageBean.getData().getName());
                binding.TVPlayDateTwo.setText(movieMessageBean.getData().getPlayDate());
                binding.TVPLayScoreTwo.setText(movieMessageBean.getData().getScore()+"分");
                binding.TVPlayTime.setText(movieMessageBean.getData().getDuration()+"分钟");
            }
        });

        List<Fragment> list = new ArrayList<>();
        List<String> tabs = Arrays.asList(new String[]{"大前天","前天","昨天","今天","明天","后天","大后天"});
        for (int i = 0; i < tabs.size(); i++) {
            list.add(ShowFragmentList.newInstance(id));
        }
        binding.TVPFShowThreater.setAdapter(getSupportFragmentManager(),getLifecycle(),list,tabs);
    }
}